﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000292 RID: 658
	internal class DoObservable<T> : OperatorObservableBase<T>
	{
		// Token: 0x06000E9A RID: 3738 RVA: 0x00044BFC File Offset: 0x00042FFC
		public DoObservable(IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
			this.onNext = onNext;
			this.onError = onError;
			this.onCompleted = onCompleted;
		}

		// Token: 0x06000E9B RID: 3739 RVA: 0x00044C27 File Offset: 0x00043027
		protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
		{
			return new DoObservable<T>.Do(this, observer, cancel).Run();
		}

		// Token: 0x0400087B RID: 2171
		private readonly IObservable<T> source;

		// Token: 0x0400087C RID: 2172
		private readonly Action<T> onNext;

		// Token: 0x0400087D RID: 2173
		private readonly Action<Exception> onError;

		// Token: 0x0400087E RID: 2174
		private readonly Action onCompleted;

		// Token: 0x02000293 RID: 659
		private class Do : OperatorObserverBase<T, T>
		{
			// Token: 0x06000E9C RID: 3740 RVA: 0x00044C36 File Offset: 0x00043036
			public Do(DoObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06000E9D RID: 3741 RVA: 0x00044C47 File Offset: 0x00043047
			public IDisposable Run()
			{
				return this.parent.source.Subscribe(this);
			}

			// Token: 0x06000E9E RID: 3742 RVA: 0x00044C5C File Offset: 0x0004305C
			public override void OnNext(T value)
			{
				try
				{
					this.parent.onNext(value);
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				this.observer.OnNext(value);
			}

			// Token: 0x06000E9F RID: 3743 RVA: 0x00044CCC File Offset: 0x000430CC
			public override void OnError(Exception error)
			{
				try
				{
					this.parent.onError(error);
				}
				catch (Exception error2)
				{
					try
					{
						this.observer.OnError(error2);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000EA0 RID: 3744 RVA: 0x00044D54 File Offset: 0x00043154
			public override void OnCompleted()
			{
				try
				{
					this.parent.onCompleted();
				}
				catch (Exception error)
				{
					this.observer.OnError(error);
					base.Dispose();
					return;
				}
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x0400087F RID: 2175
			private readonly DoObservable<T> parent;
		}
	}
}
